package com.nemodynamic.cattivial.utils;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RadialGradient;
import android.graphics.Rect;

public class ImageUtils {
	public static Bitmap getCroppedBitmap(Bitmap bitmap) {
		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(output);
		final int color = 0xff424242;
		final Paint paint = new Paint();
		final Paint paintWhite = new Paint();
		final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

		paint.setAntiAlias(true);
		paint.setDither(true);
		canvas.drawARGB(0, 0, 0, 0);
		paint.setColor(color);
		paintWhite.setAntiAlias(true);
		RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFFFFFFFF, 0xFFDDDDDD, android.graphics.Shader.TileMode.CLAMP);
		paintWhite.setShader(gradient);
		// canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
		canvas.drawCircle(bitmap.getWidth() / 2 - 3, bitmap.getHeight() / 2 - 3, bitmap.getWidth() / 2 - 3, paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
		paintWhite.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP));
		canvas.drawBitmap(bitmap, rect, rect, paint);
		canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paintWhite);
		//Bitmap _bmp = Bitmap.createScaledBitmap(output, width, height, false);
		//return _bmp;
		 return output;
	}
	
	public static Bitmap getStartButtonImages(Bitmap bitmap){
		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(output);
		final int color = 0xff424242;
		final Paint paint = new Paint();
		final Paint paintWhite = new Paint();
		final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

		paint.setAntiAlias(true);
		paint.setDither(true);
		canvas.drawARGB(0, 0, 0, 0);
		paint.setColor(color);
		paintWhite.setAntiAlias(true);
		RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFFFFFFFF, 0xFFDDDDDD, android.graphics.Shader.TileMode.CLAMP);
		paintWhite.setShader(gradient);
		canvas.drawCircle(bitmap.getWidth() / 2,  bitmap.getHeight() / 2 , bitmap.getWidth() / 2-10 , paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
		paintWhite.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP));
		canvas.drawBitmap(bitmap, rect, rect, paint);
		canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paintWhite);
		
		return output;

	}
}
